#include "dialogreguser.h"
#include "ui_dialogreguser.h"
#include "dialogrepassword.h"
#include <QDebug>
#include "../wsim_client.h"

DialogRegUser::DialogRegUser(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogRegUser)
{
    ui->setupUi(this);
}

DialogRegUser::~DialogRegUser()
{
    delete ui;
}
void DialogRegUser::setNickName(QString nickname)
{
    ui->le_nickname->setText(nickname);
}

void DialogRegUser::on_pbt_regName_clicked()
{
    DialogRePassword dlg;
    dlg.setWindowTitle(QString("申请帐户[%1],或修改密码").arg(ui->le_nickname->text()));
    if(dlg.exec()==DialogCode::Accepted)
    {
        WSIM_client::regUser(ui->le_nickname->text().toStdString(),dlg.getnewPwd().toStdString());
        WSIM_client::rePassword(ui->le_nickname->text().toStdString()
                                ,dlg.getoldPwd().toStdString(),dlg.getnewPwd().toStdString());
    }
}

void DialogRegUser::on_pbt_organ_clicked()
{
    QString str=ui->le_organ->text();
    if(str.length()>0)
    {
        WSIM_client::reOrgan(ui->le_nickname->text().toStdString(),str.toStdString());
    }
}

void DialogRegUser::on_pbt_name_clicked()
{
    QString str=ui->le_name->text();
    if(str.length()>0)
    {
        WSIM_client::reName(ui->le_nickname->text().toStdString(),str.toStdString());
    }
}

void DialogRegUser::on_pbt_mobile_clicked()
{
    QString str=ui->le_mobile->text();
    if(str.length()>0)
    {
        WSIM_client::reMobie(ui->le_nickname->text().toStdString(),str.toStdString());
    }
}
void DialogRegUser::setName(QString name)
{
    ui->le_name->setText(name);
}
void DialogRegUser::setOrgan(QString organ)
{
    ui->le_organ->setText(organ);
}
void DialogRegUser::setMobile(QString mobile)
{
    ui->le_mobile->setText(mobile);
}
void DialogRegUser::setGroups(QString groups)
{
    ui->le_groups->setText(groups);
}
